// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/elemac/api/DefaultApi'

import OneClass from '@api/elemac/model/AirboxCurveReq'

const CLIENT = CORE.grpcCLIENT(Client)

const xData = Array(25).fill().map((_, i) => `0${i}`.slice(-2)).map((x) => `${x}:00`)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne(one, TIP = '查询详情') {
    const DTO = CORE.grpcDTO(OneClass, { deviceId: one.id })
    const { curveMap = [] } = await CORE.grpc(TIP, CLIENT, 'airboxCurve', DTO)
    return { ...one, curveMap }
  },
  transOne(obj) {
    const chartDict = Object.keys(obj.curveMap).map((key) => {
      const arr = obj.curveMap[key] || []
      const { unit = '' } = arr[0] || {}
      const dataList = Array(25).fill(0)
      arr.forEach((item, i) => {
        dataList[i] = +item.value
      })
      return [key, { xData, dataList, unit }]
    })
    return { ...obj, chartDict }
  },
}
